blob: 5cafb1e3d2dc6f2c6c849713276fef4871bdeacb [file] [log] [blame]
Soares Chen5dbbd5f2017-07-10 09:56:091<!doctype html>
2<meta charset=utf-8>
3<title>RTCPeerConnection.prototype.setLocalDescription rollback</title>
4<script src="/resources/testharness.js"></script>
5<script src="/resources/testharnessreport.js"></script>
6<script src="RTCPeerConnection-helper.js"></script>
7<script>
8 'use strict';
9
10 // Test is based on the following editor draft:
11 // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html
12
13 // The following helper functions are called from RTCPeerConnection-helper.js:
14 // assert_session_desc_equals
15 // test_state_change_event
16
17 /*
18 4.3.2. Interface Definition
19 [Constructor(optional RTCConfiguration configuration)]
20 interface RTCPeerConnection : EventTarget {
21 Promise<void> setLocalDescription(
22 RTCSessionDescriptionInit description);
23
24 readonly attribute RTCSessionDescription? localDescription;
25 readonly attribute RTCSessionDescription? currentLocalDescription;
26 readonly attribute RTCSessionDescription? pendingLocalDescription;
27
28 Promise<void> setRemoteDescription(
29 RTCSessionDescriptionInit description);
30
31 readonly attribute RTCSessionDescription? remoteDescription;
32 readonly attribute RTCSessionDescription? currentRemoteDescription;
33 readonly attribute RTCSessionDescription? pendingRemoteDescription;
34 ...
35 };
36
37 4.6.2. RTCSessionDescription Class
38 dictionary RTCSessionDescriptionInit {
39 required RTCSdpType type;
40 DOMString sdp = "";
41 };
42
43 4.6.1. RTCSdpType
44 enum RTCSdpType {
45 "offer",
46 "pranswer",
47 "answer",
48 "rollback"
49 };
50 */
51
52 /*
53 4.3.1.6. Set the RTCSessionSessionDescription
54 2.2.2. If description is set as a local description, then run one of the
55 following steps:
56 - If description is of type "rollback", then this is a rollback. Set
57 connection.pendingLocalDescription to null and signaling state to stable.
58 */
59 promise_test(t=> {
60 const pc = new RTCPeerConnection();
61
62 test_state_change_event(t, pc, ['have-local-offer', 'stable']);
63
64 return pc.createOffer()
65 .then(offer => pc.setLocalDescription(offer))
66 .then(() => {
67 assert_equals(pc.signalingState, 'have-local-offer');
68 assert_not_equals(pc.localDescription, null);
69 assert_not_equals(pc.pendingLocalDescription, null);
70 assert_equals(pc.currentLocalDescription, null);
71
72 return pc.setLocalDescription({ type: 'rollback' });
73 })
74 .then(() => {
75 assert_equals(pc.signalingState, 'stable');
76 assert_equals(pc.localDescription, null);
77 assert_equals(pc.pendingLocalDescription, null);
78 assert_equals(pc.currentLocalDescription, null);
79 });
80 }, 'setLocalDescription(rollback) from have-local-offer state should reset back to stable state');
81
Soares Chenc94ef3e2017-07-14 05:20:2082 /*
83 4.3.1.6. Set the RTCSessionSessionDescription
84 2.3. If the description's type is invalid for the current signaling state of
85 connection, then reject p with a newly created InvalidStateError and abort
86 these steps. Note that this implies that once the answerer has performed
87 setLocalDescription with his answer, this cannot be rolled back.
88
89 [jsep]
90 4.1.8.2. Rollback
91 - Rollback can only be used to cancel proposed changes;
92 there is no support for rolling back from a stable state to a
93 previous stable state
94 */
95 promise_test(t => {
96 const pc = new RTCPeerConnection();
97 return promise_rejects(t, 'InvalidStateError',
98 pc.setLocalDescription({ type: 'rollback' }));
99 }, `setLocalDescription(rollback) from stable state should reject with InvalidStateError`);
100
101 promise_test(t => {
102 const pc = new RTCPeerConnection();
Rick Waldron5445fa32017-08-30 21:53:59103 return pc.createOffer({ offerToReceiveAudio: true })
Soares Chenc94ef3e2017-07-14 05:20:20104 .then(offer =>
105 pc.setRemoteDescription(offer)
106 .then(() => pc.createAnswer()))
107 .then(answer => pc.setLocalDescription(answer))
108 .then(() => {
109 return promise_rejects(t, 'InvalidStateError',
110 pc.setLocalDescription({ type: 'rollback' }));
111 });
112 }, `setLocalDescription(rollback) after setting answer description should reject with InvalidStateError`);
113
114 promise_test(t => {
115 const pc = new RTCPeerConnection();
116 return pc.createOffer()
117 .then(offer => pc.setLocalDescription(offer))
118 .then(() => pc.setLocalDescription({
119 type: 'rollback',
120 sdp: '!<Invalid SDP Content>;'
121 }));
122 }, `setLocalDescription(rollback) should ignore invalid sdp content and succeed`);
Soares Chen5dbbd5f2017-07-10 09:56:09123</script>